import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== antd
const $cache = $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		taps:[],
		forms: [
			{ label: '项目名称',			name: 'kind_name',		type: 'select',		data: this.props.level,},
			{ label: '条码号',			name: 'spec_code',		data: this.props.status },
			{ label: '是否加做项目',		name: 'op_type',		type: 'select',		data: this.props.notice },
		]
	}
	
	model = {}
	
	componentDidMount(){
		this.getSelect()
		if(window.isInit){
		  this.fetch()
		}
	}
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 项目名称
			$fn.setRow(forms, 'kind_name',  await f.getCache({ api:'common/getKindList4Select', param:{category: 'Y,Z,D'},way:'get',refresh:true }))
			// 是否加做项目
			const statusData = $fn.setRow(forms, 'op_type',  await f.add_subtract)
			this.setState({ forms, statusData })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'sp-additional/index', { isIndex: true })
	
	cols = [
		{ title: '项目名称', 	dataIndex: 'kind_name', 	width:300 },
		{ title: '条码号', 		dataIndex: 'spec_code', 	...$fn.table.spec_code},
		{ title: '操作人', 		dataIndex: 'empl_name', 	...$fn.table.name},
		{ title: '操作时间', 	dataIndex: 'op_time', 		...$fn.table.time},
		{ title: '备注', 		dataIndex: 'op_reason', 	width:200, 	align:'center' },
		{ title: '是否加做', 	dataIndex: 'op_type', 		width:200, 	align:'center', render:text => $fn.getState(this.state.statusData, text) },
	]
	
	render(){
		return (
			<>
				{/* 搜索 */}
				{ SearchForm.call(this) }
				{/* 表格 */}
				{ Table.call(this, { isIndex: true, isInit: window.isInit }) }
			</>
		)
	}
}

export default Index